class SyncLoopHook { // 钩子是同步的
    constructor(args) { // args => ['name']
        this.tasks = []
    }
    call(...args) {
        this.tasks.forEach(task => {
            let ret
            do {
                ret = task(...args)
            } while (ret != undefined);
        })
    }
    tap(name, task) {
        this.tasks.push(task)
    }
}

let hook = new SyncLoopHook(['name'])
let total = 0
hook.tap('react', function(name) {
    console.log('react', name)
    return ++ total === 3 ? undefined : 'react ok'
})
hook.tap('node', function(name) {
    console.log('node', name)
    // return 'node ok'
})
hook.tap('webpack', function(name) {
    console.log('webpack', name)
})
hook.call('jw')